package com.example.demo.util;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyStringUtil {

    /**
     * 过滤非数字
     *
     * @param str
     * @return
     */
    public static String getNumeric(String str) {
        str = str.trim();
        String str2 = "";
        if (str != null && !"".equals(str)) {
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
                    str2 = String.valueOf(str.charAt(i));
                }
            }
        }
        return str2;
    }

    /**
     * 过滤非数字
     *
     * @param str
     * @return
     */
    public static String getNumeric1(String str) {
        String regEx = "[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.replaceAll("").trim();
    }


    /**
     * 过滤非数字和小数点
     *
     * @param str
     * @return
     */
    public static String getNumericPoints(String str) {
        char[] charArr = str.toCharArray();
        String result = "";
        for (int i = 0; i < charArr.length; i++) {
            if (("0123456789.").indexOf(charArr[i] + "") != -1) {
                result = String.valueOf(charArr[i]);
            }
        }
        return result;
    }


    public static void main(String[] args) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                2,//线程池常驻线程数
                5,//线程池最大线程数
                10L,//存活时间
                TimeUnit.SECONDS,//存活时间单位
                new LinkedBlockingQueue<Runnable>(10),//阻塞队列
                Executors.defaultThreadFactory(),//线程工厂，用以创建线程
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略
        );
        try {
            for (int i = 0; i < 10; i++) {
                poolExecutor.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "办理业务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            poolExecutor.shutdown();
        }

        Integer[] is = new Integer[]{23, 43, 129, 9824, 2323, 1123, 9999, 864, 8848, 9527};
    }
}
